 package com.ytkj.digitalConstruction.service.constructionprocess;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ytkj.digitalConstruction.dao.constructionprocess.ConstructionConcentrateMapper;
import com.ytkj.digitalConstruction.entity.constructionprocess.ConstructionConcentrate;
import com.ytkj.digitalConstruction.entity.user.User;
import com.ytkj.digitalConstruction.httpbean.constructionprocess.resbean.WholeFlowInfo;

/**
 * @ClassName: ConstructionProcessService 
 * @Description: 流程具体进度处理服务
 * @author 宁煜
 * @date 2017年12月5日 上午11:07:31 
 *
 */
@Service
@Transactional
public class ConstructionConcentrateService {

	@Autowired
	private ConstructionBaseService constructionBaseService;
	
	@Autowired
	private ConstructionConcentrateMapper constructionConcentrateMapper;
	
	@Autowired
	private ConstructionConcentrateNoticeService constructionConcentrateNoticeService;

	/**
	 * @Description: 集结信息存入数据库，并跳转至下一节点同时发送消息
	 * @Title: setConcentrate 
	 * @param @param concentrate
	 * @param @return 
	 * @return WholeFlowInfo
	 * @throws
	 */
	public WholeFlowInfo setConcentrate(Integer flowId, User user){
		constructionBaseService.checkProcess(flowId, 7);
		// 补全集结信息并添加至数据库
		ConstructionConcentrate concentrate = new ConstructionConcentrate();
		concentrate.setFlowId(flowId);
		concentrate.setMaterialPiling(1);
		concentrate.setPersonnelAggregation(1);
		concentrate.setStatus(1);
		patchConcentrate(concentrate, user);
		constructionConcentrateMapper.insertSelective(concentrate);
		ConstructionUtilService.isAddSuccess(concentrate.getConcentrationId());
		WholeFlowInfo flowInfo = constructionBaseService.processNext(concentrate.getFlowId(), user);
		constructionConcentrateNoticeService.noticeRiskEdc(flowId, flowInfo, user);
		return flowInfo;
	}

	/**
	 * @Description: 补全参数信息
	 * @Title: patchConcentrate 
	 * @param @param concentrate
	 * @param @param user 
	 * @return void
	 * @throws
	 */
	public void patchConcentrate(ConstructionConcentrate concentrate, User user) {
		concentrate.setOperator(String.valueOf(user.getUserId()));
		concentrate.setUpdateBy(user.getUserId());
		concentrate.setUpdateDate(new Date());
	}
	
}
